<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>重点关注-指标查询</title>
    <link rel="stylesheet" href="/layui/v10/layui.css" media="all">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div>
    <form id="searchForm" class="layui-form" method="post" style="margin-left: 10px">
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-xs3">
                    <label for="nsrsbh"></label><input type="text" id="nsrsbh" class="layui-input" autocomplete="off"
                                                       placeholder="请输入纳税人识别号">
                </div>
                <div class="layui-col-xs3">
                    <label>
                        <select name="option" lay-verify="required">
                            <option value="" selected>请选择指标</option>
                            <option value="1">费用变化率指标</option>
                            <option value="2">毛利率指标</option>
                            <option value="3">期间费用率指标</option>
                            <option value="4">收入变化率指标</option>
                        </select>
                    </label>
                </div>
                <div class="layui-col-xs2">
                    <label for="yearPicker"></label>
                    <input type="text" class="layui-input" id="yearPicker"
                           placeholder="请选择年度">
                </div>
            </div>
            <div class="layui-row" style="margin-top: 10px;display: flex; justify-content: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="search">查询</button>
                <button type="button" class="layui-btn" lay-submit="" lay-filter="inport" id="inport">导入纳税人查询
                </button>
                <button type="button" class="layui-btn" lay-submit="" lay-filter="reset" style="margin-left: 10px">
                    重置
                </button>
                <button type="button" class="layui-btn" lay-submit="" lay-filter="export" style="margin-left: 10px">
                    导出
                </button>
            </div>
        </div>
        <table class="layui-table" id="zbTable" lay-filter="zbTable"></table>
    </form>
</div>
</body>
<script src="/layui/v10/layui.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var ajztDms;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    const upload = layui.upload;
    layui.use(['table', 'laypage', 'layer', 'laydate', 'upload'], function () {
        // 指标列表
        tableIns1 = table.render({
            elem: '#zbTable'
            , loading: false
            , page: true //开启分页
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , url: '/attention/attentionMgr/queryZbcxTable' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {field: 'jcajxxuuid', title: '主键', width: 1, hide: true},
                    {field: 'nsrsbh', title: '纳税人识别号', width: 220, align: "center"},
                    {field: 'nsrmc', title: '纳税人名称', width: 380, align: "center"},
                    {field: 'nd', title: '年度', width: 160, align: "center"},
                    {field: 'bnqjfy', title: '本年期间费用', width: 240, align: "center"},
                    {field: 'snqjfy', title: '上年期间费用', width: 240, align: "center"},
                    {field: 'fybhl', title: '费用变化率', width: 240, align: "center"},
                ]
            ]
            , toolbar: '#toolbar'
        });
        // 初始化年选择器
        laydate.render({
            elem: '#yearPicker',
            type: 'year' // 只选择年
        });
        //列表查询
        form.on('submit(search)', function (data) {
            var formData = data.field;
            console.log("data", data)
            console.log("formData", formData)
            var ajztDms = formData.ajztDm;
            var whereParams = {
                "jcajbh": $("#ajbh").val(),
                "jcaybh": $("#aybh").val(),
                "nsrsbh": $("#nsrsbh").val(),
                "nsrmc": $("#nsrmc").val(),
                "lastartTime": la_startTime,
                "laendTime": la_endTime,
                "jastartTime": ja_startTime,
                "jaendTime": ja_endTime,
                "ajjchj": ajztDms,
            };
            tableIns1.reload({
                contentType: 'application/json'
                , headers: {"authorization": token}
                , where: whereParams
                , url: '/attention/attentionMgr/queryJjajList' //数据接口
                , method: 'POST'
                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                        "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                    }
                }, page: {
                    curr: 1 //重新从第 1 页开始
                }
            }, false);
        })
        // 导入纳税人识别号查询
        upload.render({
            elem: '#inport', // 绑定按钮
            headers: {"authorization": token},
            url: '/workflow/casesource/uploadJjajExcel',  // 上传接口地址
            accept: 'file',       // 允许上传的文件类型
            exts: 'xlsx|xls',     // 允许上传的文件后缀
            done: function (res) {
                if (res.code === 0) {
                    tableIns1.reload({
                        contentType: 'application/json',
                        data: res.data.records, // 重新渲染数据
                        url: "",
                        page: {
                            curr: 1
                        }
                    });
                } else {
                    layer.alert(res.msg, {icon: 2});
                }
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
            }
        });
        //页面查询条件重置按钮
        form.on('submit(reset)', function () {
            console.log("我进来了嘛？")
            document.getElementById('searchForm').reset(); // 原生重置表单
            $('#ajbh').val(''); // 清空输入框
            $('#aybh').val(''); // 清空输入框
            $('#nsrmc').val(''); // 清空输入框
            $('#nsrsbh').val(''); // 清空输入框
            $('#lasjTime').val(''); // 清空输入框
            la_startTime = null; // 重置开始时间
            la_endTime = null; // 重置结束时间
            $('#jasjTime').val(''); // 清空输入框
            ja_startTime = null;
            ja_endTime = null;
            form.render(); // 重新渲染 Layui 的动态组件
        })
        //导出
        form.on('submit(export)', function (data) {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                var formData = data.field;
                var ajztDms = formData.ajztDm;
                var whereParams = {
                    "jcajbh": $("#ajbh").val(),
                    "jcaybh": $("#aybh").val(),
                    "nsrsbh": $("#nsrsbh").val(),
                    "nsrmc": $("#nsrmc").val(),
                    "lastartTime": la_startTime,
                    "laendTime": la_endTime,
                    "jastartTime": ja_startTime,
                    "jaendTime": ja_endTime,
                    "ajztDm": ajztDms,
                };
                CoreUtil.sendPost("/attention/attentionMgr/exportJjajList", whereParams, function (res) {
                    if (res.code === 0) {
                        const data = res.data;
                        if (!CoreUtil.isEmpty(data)) {
                            //全部导出
                            table.exportFile(tableIns1.config.id, data, 'xls');
                            //导出时阻止页面刷新
                            $(".layui-form").submit(function (e) {
                                e.preventDefault();
                            })
                        } else {
                            layer.alert('未查询到需要导出的数据！', {icon: 2});
                        }
                    }
                });
                layer.close(index);
            });
        })
    });
</script>
</html>